<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

function admin_url() {
	return  base_url() . "admin/";
}

function image_src($patch = '') {
	if(strpos($patch,'ttp://'))
		return $patch;
	return base_url().$patch;
}

function video_image($id_youtube) {
	return "https://i1.ytimg.com/vi/$id_youtube/mqdefault.jpg";
}

function page404() {
	return base_url().'404.html';
}

function theme_url($uri = '') {
	return base_url() . 'template/theme1/' . $uri;
}

function category_url($catCode, $page=0){
	if($page >1)
		return base_url().$catCode."/trang-".$page.".html";
	return base_url().$catCode.".html";
}

function program_url($programCode, $page = 0){
	if($page >1)
		return base_url().$programCode."/trang-".$page.".html";
	return base_url().$programCode.".html";
}

function series_url($seriesCode, $page = 0){
	if($page >1)
		return base_url().'series/'.$seriesCode."/trang-".$page.".html";
	return base_url().'series/'.$seriesCode.".html";
}

function video_url($videoID,$videoCode,$programCode){
	return base_url().$programCode.'/'.$videoCode.'-'.$videoID.".html";
}


function get_embeded_link($url, $type){
	try {
// 		preg_match('/([a-z\-_0-9\/\:\.]*\.(jpg|jpeg|png|gif))/',$url,  $matchs);
// 		if (count($matchs) > 0) {
// 			return
// 			$url;
// 		}
		$url_info = parse_url($url);
		$link = '';
		switch($type) {
			case 'youtube.com':
				
				$link = 'http://www.youtube.com/embed/'.$url. '?showinfo=0&iv_load_policy=3&modestbranding=1&nologo=1&autoplay=1&amp;ps=docs';
				break;
			case 'vimeo.com':
				$link = 'http://player.vimeo.com/video'.$url_info['path'].'?portrait=0';
				break;
			case 'tv.zing.vn':
				preg_match('/\/(?P<zingid>\w+).html$/',$url,  $matchs);
				if($matchs['zingid'])
					$link ='http://tv.zing.vn/embed/video/'. $matchs['zingid'];
				break;
		}
		return $link;
	}
	catch (Exception  $e){return '';}
}

function prd() {
	echo "<pre>";
	print_r(func_get_args());
	echo "<pre>";
	$bt = debug_backtrace();
	$caller = array_shift($bt);
	echo "<div style='color:red' >Call from: " . $caller['file'] ."(". $caller['line'].")</div>";
	die();
}

function gif_url($gif_id) {
	return base_url(). "gif/".$gif_id;
}